import { defineStore } from 'pinia';
import { GlobalMode } from './type';

const useGlobalModeStore = defineStore('global-model', {
  state: (): GlobalMode => {
    return {
      mode: '',
    };
  },
  getters: {
    getGlobalMode(state: GlobalMode) {
      return state.mode;
    },
  },
  actions: {
    changeGlobalMode(mode: string) {
      if (mode) {
        this.mode = mode;
        localStorage.setItem('global_mode', mode);
      }
    },
    initGlobalMode() {
      const mode: string = localStorage.getItem('global_mode') || 'design';
      this.changeGlobalMode(mode);
    },
  },
});

export default useGlobalModeStore;
